package com.example.feidaolumanager.pages.ui.index

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.paint
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.fragment.app.FragmentActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.NavigationUI
import com.example.feidaolumanager.R
import com.google.android.material.bottomnavigation.BottomNavigationView

/**
 * Created with IntelliJ IDEA.
 * @Author: Liao Run
 * @Date: 2024-04-01 11:39
 * @Description:
 **/
@Composable
fun MachineCountCard(name: String, count: Int, countColor: Color, activity: FragmentActivity?) {
    Column(
        Modifier
            .height(110.dp)
            .padding(start = 6.dp, end = 6.dp)
            .clip(RoundedCornerShape(6.dp))
            .paint(
                painterResource(id = R.drawable.bg),
                contentScale = ContentScale.FillBounds
            )
            .clickable {
                // 使用BottomNavigationView跳转到MapFragment
                val bottomNavigationView =
                    activity?.findViewById<BottomNavigationView>(R.id.nav_view)

                if (bottomNavigationView != null) {
                    NavigationUI.onNavDestinationSelected(
                        bottomNavigationView.menu.getItem(1),
                        activity.findNavController(R.id.nav_host_fragment_activity_main)
                    )
                }

            }
    ) {
        Spacer(modifier = Modifier.height(20.dp))
        Text(
            text = name,
            color = Color.White,
            fontSize = 14.sp,
            modifier = Modifier.padding(start = 6.dp)
        )
        Text(
            text = count.toString(),
            fontSize = 20.sp,
            color = countColor,
            modifier = Modifier.padding(start = 6.dp),
            fontWeight = FontWeight.W500
        )
    }
}